package tx.oopa.circuit.port;

/**
 * Abstract class which should be inherited by ports which have two
 * input values. This class handles the input values and eventually calls
 * the method which actually performs the logical function.
 * 
 * @author Xander van Rijn
 *
 */
public abstract class AbstractDoublePort extends AbstractPort {

    protected Boolean firstInput = null;
    protected Boolean secondInput = null;

    protected AbstractDoublePort() {}
    
    protected AbstractDoublePort(String ID) {
        super(ID);
    }
    
	/**
	 * {@inheritDoc}
	 */
    public Boolean setInput(Boolean bool) {
    	if(bool == null) {
    		throw new IllegalArgumentException("Input value cannot be null.");
    	}
        if(firstInput == null) {
            firstInput = bool;
        } else {
            secondInput = bool;
        }
        if(firstInput != null && secondInput != null) {
            return performLogicalFunction();
        }
        return null;
    }
}
